#include <stdio.h>

#define rep(i,n) for (int i=0; i<n; i++)

int low[30];
int up[30];
int max;
char c;

int main() {
	while (scanf("%c", &c)!=EOF) {
		if (c=='\n') {
			max=-1;

			rep(i,30) if (max<low[i]) max=low[i];
			rep(i,30) if (max<up[i]) max=up[i];

			rep(i,30) if (up[i]==max) printf("%c", 'A'+i);
			rep(i,30) if (low[i]==max) printf("%c", 'a'+i);
			
			printf(" %d\n", max);

			rep(i,30) low[i]=0;
			rep(i,30) up[i]=0;
		}
		else if (c>='a' && c<='z') {
			low[c-'a']++;
		}
		else if (c>='A' && c<='Z') {
			up[c-'A']++;
		}
	}

	return 0;
}
